package com.drama.api.sys.recycle.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.drama.api.base.*;
import com.drama.api.company.video.domain.vo.CompanyVideoSearchVO;
import com.drama.api.company.video.domain.vo.CompanyVideoVO;
import com.drama.api.company.video.service.ICompanyVideoService;
import com.drama.util.BindingResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@Api( tags = ApiIndex.SysRecycleVideoController)
@RequestMapping(value = "/api/sys/recycle_video")
@RestController
@SaCheckLogin
public class SysRecycleVideoController {

    @Autowired
    private ICompanyVideoService service;

    @ApiOperation(value = "查询视频列表")
    @GetMapping(value = "/list")
    public R<RestPage<List<CompanyVideoVO>>> list(
            @ApiParam(value = "查询参数") @ModelAttribute CompanyVideoSearchVO searchVO) {
        List<CompanyVideoVO> list = service.getRecycleList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }


    @ApiOperation(value = "删除视频[彻底删除-清除资源]")
    @PostMapping(value = "/delete")
    public R delete(@ApiParam(value = "参数") @Valid @RequestBody IDEntity idEntity, BindingResult bindingResult) {
        R result = BindingResultUtil.BindingResult(bindingResult);
        if (result.getCode() == Constants.SYS_SUCCESS) {
            service.deletes(idEntity.getId());
        }
        return result;
    }


    @ApiOperation(value = "恢复视频")
    @PostMapping(value = "/recover")
    public R recover(@ApiParam(value = "参数") @Valid @RequestBody IDEntity idEntity, BindingResult bindingResult) {
        R result = BindingResultUtil.BindingResult(bindingResult);
        if (result.getCode() == Constants.SYS_SUCCESS) {
            service.recover(idEntity.getId());
        }
        return result;
    }



}
